//
// Created by xili on 2024/8/7 11:13.
// Go big or go home.
//
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

class Solution {
public:
    int specialArray(vector<int> &nums) {
        sort(nums.begin(), nums.end(), greater<int>());
        int n = nums.size();
        for (int i = 1; i <= n; ++i) {
            if (nums[i - 1] >= i && (i == n || nums[i] < i)) {
                return i;
            }
        }
        return -1;
    }
};